package Plain;

import java.awt.Color;
import java.awt.Graphics;

import util.Constant;

public class Bullet extends GameObject{
	double degree;
	
	public Bullet() {
		this.x = (Constant.GAME_WIDTH - Constant.BULLET_SIZE)  / 2;
		this.y = (Constant.GAME_HEIGHT - Constant.BULLET_SIZE - 30) / 2;
		this.height = this.width = Constant.BULLET_SIZE;
		this.speed = Constant.BULLET_SPEED;
		this.degree = Math.random() * Math.PI * 2.0;
		
		System.out.println("Bullet x = " + x + "y = " + y + "width" + width + "height" + height);
	}
	
	public void draw(Graphics g) {
		Color c = g.getColor();
		g.setColor(Color.YELLOW);
		g.fillOval((int)x, (int)y, width, height);
		
		x += speed * Math.cos(degree);
		y += speed * Math.sin(degree);
		
		if(x > Constant.GAME_WIDTH - this.width - Constant.FRAME_SIZE_OTHER || x < Constant.FRAME_SIZE_OTHER) {
			degree = Math.PI - degree ;
		}
		
		if(y > Constant.GAME_HEIGHT - this.height - Constant.FRAME_SIZE_OTHER || y < Constant.FRAME_SIZE_UP) {
			degree = -degree;
		}
		g.setColor(c);
	}
}
